package top.lisicheng.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import top.lisicheng.service.IProviderSendService;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @author Lisicheng
 */
@EnableBinding(Source.class)
public class ProviderSendServiceImpl implements IProviderSendService {

    // @Qualifier("output")
    // @Autowired
    @Resource(name = "output")
    private MessageChannel messageChannel;

    @Override
    public void send() {

        String message = UUID.randomUUID().toString();

        Map<String, Object> map = new HashMap<String, Object>() {{
            put("token", message);
        }};

        messageChannel.send(MessageBuilder.createMessage(message, new MessageHeaders(map)));

        System.out.println("send message:" + message);

    }
}
